FROM modihq/yii2-dev:7.1-stretch

# --- 创建和主机登录用户相同 uid/gid 的用户 ---

ARG X_GID
ARG X_UID

RUN set -eux; \
    if [ -z "`getent group ${X_GID}`" ]; then \
        addgroup --system --gid ${X_GID} xu; \
    fi; \
    adduser --system --disabled-password --uid ${X_UID} --gid `getent group ${X_GID} | cut -d: -f3` xu

# --- 使用 xu 用户运行 PHP-FPM 的进程池 ---

RUN { \
        echo '[www]'; \
        echo; \
        echo "user = ${X_UID}"; \
        echo "group = ${X_GID}"; \
    } | tee /usr/local/etc/php-fpm.d/zzz.conf

# --- Composer ---

ENV COMPOSER_HOME /tmp/composer

RUN mkdir /tmp/composer && \
    chown xu:$X_GID /tmp/composer

# --- 定时任务 ---

COPY ./php/cron/crontab /etc/crontabs/xu

RUN chown root /etc/crontabs/xu && \
    chmod 600 /etc/crontabs/xu

WORKDIR /code

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

